package bus;

import java.util.ArrayList;

import dao.AdminDao;
import dao.StudentDao;
import dao.TeacherDao;
import dao.UserDao;
import dto.AdminDto;
import dto.StudentDto;
import dto.TeacherDto;
import dto.UserDto;

public class LoginBus {

	public static String login(String email, String pass) {
		UserDao userDao = new UserDao();
		ArrayList<UserDto> allUser = userDao.getAllUser();
		for (UserDto user : allUser) {
			if (user.getEmailAddress().equals(email)) {
				String role = user.getRole();

				switch (role) {
				case "Student":
					StudentDao studentDao = new StudentDao();
					StudentDto student = studentDao.getStudentByUserId(user
							.getUserId());
					if (student != null)
						if (student.getPassword().equals(pass))
							return "Student@#$" + student.getId();
					break;
				case "Teacher":
					TeacherDao teacherDao = new TeacherDao();
					TeacherDto teacher = teacherDao.getTeacherByUserId(user
							.getUserId());
					if (teacher.getPassword().equals(pass))
						return "Teacher@#$" + teacher.getId();
					break;
				case "Admin":
					AdminDao adminDao = new AdminDao();
					AdminDto admin = adminDao
							.getAdminByUserId(user.getUserId());
					if (admin.getPassword().equals(pass))
						return "Admin@#$" + admin.getId();
					break;
				default:
					break;
				}
			}
		}

		return "";
	}
}
